<template>
	<view class="">
	

		<view class="row">
			<view class="lists" v-for="(item,index) in list" :key="index" @click="detail(item)">
			
					<u-image :src="item.cover" width="350" height="350" ></u-image>
			
				<view class="" style="padding: 20rpx;width: 350rpx;">
					<view class="u-line-2" style="font-size: 28rpx;font-weight: bold">
						{{item.goodsName}}
					</view>
					<view class="u-flex u-row-between u-margin-top-10" >
						<view style="color: #FF6450;font-size: 30rpx;">{{item.price}}积分</view>
						<view style="color: #999;font-size: 26rpx;">仅剩{{item.sku}}件</view>
					</view>
				</view>
			</view>
		</view>
		<u-loadmore :status="status" />
    
	</view>
</template>

<script>
	
	export default {
		
		data() {
			return {
				page:1,
				status: 'loadmore',				
				list:[]
			}
		},
		onLoad() {
			this.getGoods()
		},
		
		onPullDownRefresh() {
			this.page = 1;
			this.getGoods()
			setTimeout(function() {
				uni.stopPullDownRefresh()
			}, 1000)
		},
		onReachBottom() {
			if (this.status == 'nomore') {
		
			} else {
				this.getGoods()
			}
		
		},
		methods: {
		
			detail(item){
				console.log(item)
				uni.navigateTo({
					url:"./detail?id="+ item.id
				})
			},
			// 获得商品
			getGoods() {
				this.$u.post('/api/index/goods', {
			        goods_type:2,				
		            page:this.page,		
				}, {}).then(res => {
					var resList = res.data;
					if (this.page == 1) {
						this.list = []
					}
					if (resList.length > 9) {
						this.status = 'loadmore'
						this.page = this.page + 1
					} else {
						this.status = 'nomore'
					}
					this.list = this.list.concat(resList)
					this.loading = false
				}).catch(err => {})
			},
			
		}
	}
</script>

<style lang="scss">

	.row{
		display: flex;
		justify-content: space-between;
		padding: 20rpx;
		flex-wrap: wrap;
	
	}
	.lists{
		background: #FFFFFF;
		box-shadow: 0px 4rpx 6rpx rgba(209, 209, 209, 0.26);
		border-radius: 20rpx;
		margin-bottom: 20rpx;
	}
</style>
